package com.vito.demo.sb2.web.controller

import com.vito.demo.sb2.business.services.NewsService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseBody

/**
 * Created by lingzhiyuan.
 * Date : 16/3/31.
 * Time : 下午2:42.
 * Description:
 *
 */

@Controller
class BasicController @Autowired constructor(val newsService: NewsService) {

    @RequestMapping("/")
    fun toIndex(): String {
        return "index"
    }

    @RequestMapping("/newses")
    @ResponseBody
    fun findAllNewes(@RequestParam(required = false, defaultValue = "3")
                     count: Int): Any
//            = newsService.findAllNews()
            = """
getZoneInfo([{"id":"city2","value":{"101":"B \u5317\u4eac"},"py":{"101":"beijing"},"defval":101,"ishot":{"101":"1"}},{"id":"city2","value":{"101010100":"B \u5317\u4eac","101010200":"H \u6d77\u6dc0","101010300":"C \u671d\u9633","101010400":"S \u987a\u4e49","101010500":"H \u6000\u67d4","101010600":"T \u901a\u5dde","101010700":"C \u660c\u5e73","101010800":"Y \u5ef6\u5e86","101010900":"F \u4e30\u53f0","101011000":"S \u77f3\u666f\u5c71","101011100":"D \u5927\u5174","101011200":"F \u623f\u5c71","101011300":"M \u5bc6\u4e91","101011400":"M \u95e8\u5934\u6c9f","101011500":"P \u5e73\u8c37","101011501":"D \u4e1c\u57ce\u533a","101011502":"X \u897f\u57ce\u533a"},"py":{"101010100":"beijing","101010700":"changping","101010300":"chaoyang","101011100":"daxing","101011501":"dongchengqu","101011200":"fangshan","101010900":"fengtai","101010200":"haidian","101010500":"huairou","101011400":"mentougou","101011300":"miyun","101011500":"pinggu","101011000":"shijingshan","101010400":"shunyi","101010600":"tongzhou","101011502":"xichengqu","101010800":"yanqing"},"defval":101010100,"ishot":{"101010100":"1","101010200":"0","101010300":"0","101010400":"0","101010500":"0","101010600":"0","101010700":"0","101010800":"0","101010900":"0","101011000":"0","101011100":"0","101011200":"0","101011300":"0","101011400":"0","101011500":"0","101011501":"0","101011502":"0"}}])"""

    @RequestMapping("save")
    @ResponseBody
    fun saveNews(@RequestParam() title: String, @RequestParam() content:
    String): Boolean {
        var result = newsService.save(title, content)

        return result
    }

}

